package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.AcceptInfo;
import com.example.demo.entity.ReturnStatus;
import com.example.demo.entity.UserBasicInfo;
import com.example.demo.entity.UserFeedbackInfo;
import com.example.demo.mapper.UserMapper;
import lombok.Data;
import java.lang.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/backendapi")
public class BackendControllor {

    @Resource
    UserMapper userMapper;
    static String name;
    @Data
    static class USER{
        String userphone;
        String nickname;
        String userid;
    }
    @Data
    static class FEEDBACK{
        Integer feedbackid;
    }

    @GetMapping ("/find_all_user_info")//查看所有用户信息
    public List<UserBasicInfo> find_all_accept_info(){return userMapper.find_all_user_basic_info(); }


    @PostMapping("/find_userinfo_by_phone")//通过手机号查看用户信息
    public List<UserBasicInfo> find_user(@RequestBody USER user){return userMapper.find_user_by_id(user.userphone);}

    @PostMapping("/update_user_by_phone")//通过手机号修改用户信息
    public ReturnStatus<String> add_user(@RequestBody UserBasicInfo user){
       if(userMapper.update_user_basic(user)) return new ReturnStatus<String> (1,null);
       else return new ReturnStatus<String> (0,null);
    }

    @PostMapping("/find_feedback_by_id")//通过用户id查看反馈
    public List<UserFeedbackInfo> findFeedBackByID(@RequestBody USER user){
        return userMapper.findFeedBackByid(user.userid);
    }

    @PostMapping("/update_feedback_by_Id")//根据Id将用户反馈改为已查看
    public ReturnStatus<String> have_viewed (@RequestBody FEEDBACK feedback){
        if(userMapper.update_feedback_by_id(feedback.feedbackid))return  new ReturnStatus<String>(1,null);
        else return new ReturnStatus<String>(0,null);
    }

    @GetMapping ("/find_unviewed")
    public List<UserFeedbackInfo> find_unviewed (){
        return userMapper.find_unviewed();
    }

    @GetMapping ("/find_viewed")
    public List<UserFeedbackInfo> find_viewed (){
        return userMapper.find_viewed();
    }






    
}
